package com.xs.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xs.entity.Article;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 文章的访问
 */
@Repository
@Mapper
public interface ArticleDao extends BaseMapper<Article> {
    //收藏
    @Select("SELECT a.* FROM collection c left join  article a on a.id = c.article_id where c.uid = #{uid}")
    List<Article> selectCollectionArticle(@Param("uid") Integer uid);

    //通过用户id获取5篇用户所写的文章
    @Select("select a.* from article a where uid=#{id} and a.cover=0 order by a.id desc limit 5")
    List<Article> findUsersArticleBynickname(@Param("id") Integer id);

    //查询5篇用户预览最多类型的文章
    @Select("select * from article a where a.tid=#{tid} order by a.readnumber desc limit 5")
    List<Article> recommandArticle(Integer tid);

    //随机抽取5篇cover为0的文章
    @Select("SELECT * FROM article  WHERE cover=0 ORDER BY RAND() LIMIT 5;")
    List<Article> reArticle();

    //查询公告信息
    @Select("SELECT * FROM  article WHERE cover=3 ORDER BY id ASC LIMIT 5")
    List<Article> announceArticle();
}
